package com.jinlia.show.modules.base.model.po;


import com.jinlia.show.common.core.utils.CacheUtils;
import com.jinlia.show.modules.base.system.entity.Goods;
import com.jinlia.show.modules.base.system.entity.GoodsLabel;
import lombok.Data;
import org.springframework.beans.BeanUtils;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.function.Supplier;

@Data
public class GoodsPO extends Goods {

    private String goodsTypeName;
    private List<GoodsAttrPO> goodsAttrPOS;
    /**
     * 标签名
     */
    private List<GoodsLabel> tags;

    public static GoodsPO fromEntity(Goods goods) {
        GoodsPO goodsVO = new GoodsPO();
        BeanUtils.copyProperties(goods, goodsVO);
        return goodsVO;
    }

    public static Goods toEntity(GoodsPO vo) {
        Goods entity = new Goods();
        BeanUtils.copyProperties(vo, entity);
        return vo;
    }
    public String getGoodsTypeName() {
        if (!ObjectUtils.isEmpty(this.getGoodsType())) {
            goodsTypeName = CacheUtils.fromTable("name", "erp_goods_type", this.getGoodsType());
        }
        return goodsTypeName;
    }

    public void filedVO(Supplier<String>... methodReference) {
        for (Supplier<String> stringSupplier : methodReference) {
            stringSupplier.get();
        }
    }
}
